package com.eastfair.venuebooking.service.impl;

import com.eastfair.common.dto.AttachmentFileDTO;
import com.eastfair.common.dto.AttachmentFileSaveDTO;
import com.eastfair.common.vo.AttachmentFileVO;
import com.eastfair.core.base.R;
import com.eastfair.core.utils.ConvertUtil;
import com.eastfair.pay.api.AttachmentFileFeign;
import com.eastfair.venuebooking.enums.VenueBookingMoudleEnum;
import com.eastfair.venuebooking.service.DrawingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 业务实现类
 * 场地图纸
 * </p>
 *
 * @author lyw
 * @date 2022-06-29
 */
@Slf4j
@Service
public class DrawingServiceImpl implements DrawingService {
    @Autowired
    private AttachmentFileFeign attachmentFileFeign;




    @Override
    public List<AttachmentFileVO> getDrawingList(AttachmentFileDTO attachmentFileDTO) {
        attachmentFileDTO.setBusinessType(VenueBookingMoudleEnum.SPACE_DRAWING.getCode());
        R<List<AttachmentFileVO>> listR = attachmentFileFeign.queryAttachmentFile(attachmentFileDTO);
        Collections.reverse(listR.getData());
        return listR.getData();
    }

    /**
     * 添加图纸信息
     *
     * @param attachmentFileSaveDTOList
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveDrawingInfo(List<AttachmentFileSaveDTO> attachmentFileSaveDTOList) {
        Boolean flag =Boolean.FALSE;
        if (Objects.nonNull(attachmentFileSaveDTOList) && attachmentFileSaveDTOList.size()>0) {
            attachmentFileSaveDTOList.forEach((s)->{
                s.setBusinessType(VenueBookingMoudleEnum.SPACE_DRAWING.getCode());
            });
            List<AttachmentFileDTO> attachmentFileDTOS = ConvertUtil.convertList(attachmentFileSaveDTOList, AttachmentFileDTO.class);
            //添加展厅图纸附件
            attachmentFileFeign.addAttachmentFile(attachmentFileDTOS);
            flag=Boolean.TRUE;
        }
        return flag;
    }

    /**
     * 删除图纸
     * @param ids
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean delDrawingById(List<Long> ids) {
        Boolean flag =Boolean.FALSE;
        if(ids.size()>0){
           ids.forEach((s)->{
               attachmentFileFeign.detele(s);
           });
            flag=Boolean.TRUE;
        }

        return flag;
    }
}
